package com.ladlee.validata;

import lombok.Data;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * @Auther: dingchang
 * @Date: 2018/12/21 14:32
 * @Description: 验证码的基类
 */
@Data
public class ValidateCode implements Serializable {

    private static final long serialVersionUID = 271651229906277497L;

    private String code;//具体的验证码

    private LocalDateTime expireTime;//过期时间

    public ValidateCode(String code, LocalDateTime expireTime) {
        this.code = code;
        this.expireTime = expireTime;
    }

    public ValidateCode(String code, int expireIn) {
        this.code = code;
        this.expireTime = LocalDateTime.now().plusSeconds(expireIn);//当前时间 + 秒数 = 过期的时间
    }

    /**
     * 判断验证码是否过期
     * @return
     */
    public boolean isExpired(){
        return LocalDateTime.now().isAfter(expireTime);
    }

}
